package com.j2110.dao;

import com.j2110.pojo.Emp;
import com.j2110.utils.DSUtil;

import java.util.List;

public class EmpDao {

    //查询所有
    public List<Emp> query(){
        List<Emp> list = DSUtil.query("select * from emp", Emp.class);
        return list;
    }

    //添加学生
    public int execute(Emp emp){
        return DSUtil.execute("insert into emp values (null,?,?,?,?,?,?)", emp.getName(), emp.getAge(), emp.getSex(),
                emp.getAddress(), emp.getTel(), emp.getCard());
    }
    //删除学生
    public int delete(String id){
        return DSUtil.execute("delete from emp where id = ?", id);
    }

    //修改
    public int update(Emp emp){
        return DSUtil.execute("update  emp set name = ?,sex = ?,address = ?,tel = ?,card = ? where id = ?",
                emp.getName(),emp.getSex(),emp.getAddress(),emp.getTel(),emp.getCard(),emp.getId());
    }

    public List<Emp> queryById(String id) {
        return DSUtil.query("select * from emp where id = ?", Emp.class, id);
    }

    public List<Emp> queryByName(String name) {
        return DSUtil.query("select * from emp where name = ?", Emp.class, name);
    }
}
